package com.huawei.appmarket.framework.widget.uxwidget.hwdotspageindicator;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;

import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import java.lang.reflect.Field;
import o.dkp;
import o.dkq;
import o.dky.c;
import o.dky.d;
import o.dky.o;
import o.Logger;
import o.ContentManager;
import o.epr;
import o.epv;
import o.MinimumFactory;
import o.kk;

public class HwTopBannerIndicator extends View implements OnPageChangeListener {
    private float ʻ;
    private float ʻॱ;
    private int ʼ;
    private float ʼॱ;
    private int ʽ;
    private Paint ʽॱ;
    private boolean ʾ;
    private float[] ʿ;
    private boolean ˈ;
    private Paint ˉ;
    private int ˊ;
    private boolean ˊˊ;
    private int ˊˋ;
    private float ˊॱ;
    private int ˊᐝ;
    private float ˋ;
    private Paint ˋˊ;
    private float ˋˋ;
    private float ˋॱ;
    private boolean ˋᐝ;
    private boolean ˌ;
    private dkp ˍ;
    private int ˎ;
    private boolean ˎˎ;
    public boolean ˏ;
    private Runnable ˏˏ;
    private float ˏॱ;
    private float ͺ;
    private boolean ॱ;
    private int ॱˊ;
    private int ॱˋ;
    private int ॱˎ;
    private float ॱॱ;
    private OnPageChangeListener ॱᐝ;
    private Handler ᐝ;
    private ViewPager ᐝॱ;

    public HwTopBannerIndicator(Context context) {
        this(context, null);
    }

    public HwTopBannerIndicator(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwTopBannerIndicator(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˏ = true;
        this.ʾ = false;
        this.ˋᐝ = false;
        this.ˎˎ = false;
        this.ˌ = false;
        this.ˏˏ = new 4(this);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, o.ˈॱ, i, 0);
        this.ˋ = obtainStyledAttributes.getFloat(o.ˎͺ, 0.0f);
        this.ʼ = obtainStyledAttributes.getColor(o.ˋʼ, getResources().getColor(d.ˊˋ));
        this.ʽ = obtainStyledAttributes.getColor(o.ˋʽ, getResources().getColor(d.ᐝ));
        this.ˊॱ = obtainStyledAttributes.getDimension(o.ˌॱ, (float) getResources().getDimensionPixelSize(c.ˑ));
        this.ˏॱ = obtainStyledAttributes.getDimension(o.ˊʽ, (float) getResources().getDimensionPixelSize(c.ˍ));
        this.ॱॱ = obtainStyledAttributes.getDimension(o.ͺˏ, (float) getResources().getDimensionPixelSize(c.ˌ));
        this.ˊˋ = obtainStyledAttributes.getInt(o.ˋʻ, 0);
        this.ॱˊ = obtainStyledAttributes.getColor(o.ͺˎ, getResources().getColor(d.ˊˊ));
        this.ͺ = obtainStyledAttributes.getDimension(o.ˊʼ, (float) getResources().getDimensionPixelSize(c.ˋᐝ));
        this.ˊˊ = obtainStyledAttributes.getBoolean(o.ˑॱ, false);
        this.ˊᐝ = obtainStyledAttributes.getInt(o.ˏͺ, 0);
        obtainStyledAttributes.recycle();
        ˊ();
    }

    private void ˊ() {
        Resources resources = getResources();
        boolean z = this.ˊᐝ == 0 && (this.ˊˊ || epr.ˎ().ॱॱ());
        this.ˌ = z;
        this.ˎ = resources.getDimensionPixelSize(c.ˎˎ);
        this.ˊ = resources.getDimensionPixelSize(c.ˋˋ);
        this.ʻ = this.ˊॱ * 2.0f;
        this.ˋॱ = this.ˏॱ * 2.0f;
        this.ʽॱ = new Paint(1);
        this.ʽॱ.setColor(this.ʼ);
        this.ˉ = new Paint(1);
        this.ˉ.setColor(this.ʽ);
        this.ˋˊ = new Paint(1);
        this.ˋˊ.setColor(this.ॱˊ);
        this.ˋˊ.setStrokeWidth(this.ͺ);
        this.ˋˊ.setStyle(Style.STROKE);
        addOnAttachStateChangeListener(new 2(this));
    }

    private void ʽ() {
        this.ᐝ = new Handler();
    }

    public void setViewPager(ViewPager viewPager, int i) {
        if (viewPager == null || viewPager.getAdapter() == null) {
            Logger.ˋ("HwTopBannerIndicator", "setViewPage, viewPager = " + viewPager);
            return;
        }
        this.ᐝॱ = viewPager;
        ˋ(i);
        ˊ(viewPager);
        viewPager.getAdapter().ˊ(new 1(this));
        viewPager.setOnPageChangeListener(this);
        ˊॱ();
        if (this.ˋᐝ) {
            ˏॱ();
        }
        this.ᐝॱ.setOnTouchListener(new c(this, null));
    }

    private void ˊ(ViewPager viewPager) {
        try {
            Field declaredField = ViewPager.class.getDeclaredField("mScroller");
            declaredField.setAccessible(true);
            declaredField.set(viewPager, new dkq(viewPager.getContext(), new kk()));
            declaredField.setAccessible(false);
        } catch (Throwable e) {
            Logger.ˋ("HwTopBannerIndicator", "mScroller set error.", e);
        }
    }

    private boolean ʼ() {
        return this.ˎˎ;
    }

    public void setBoolean(boolean z) {
        this.ˎˎ = z;
    }

    public boolean ˎ() {
        return this.ॱ;
    }

    public void ˋ() {
        if (this.ʾ && !this.ॱ) {
            this.ॱ = true;
            if (this.ᐝ == null) {
                ʽ();
            }
            this.ᐝ.removeCallbacks(this.ˏˏ);
            this.ᐝ.postDelayed(this.ˏˏ, (long) ((int) this.ˋ));
        }
    }

    public void ॱ() {
        this.ॱ = false;
        if (this.ᐝ != null) {
            this.ᐝ.removeCallbacks(this.ˏˏ);
        }
        this.ᐝ = null;
    }

    private void ˎ(int i) {
        if (i == 0) {
            if (this.ˋ > 0.0f) {
                this.ᐝ.post(this.ˏˏ);
            } else {
                ॱ();
            }
        } else if (this.ˋ > 0.0f) {
            this.ᐝ.postDelayed(this.ˏˏ, (long) ((int) this.ˋ));
        } else {
            ॱ();
        }
    }

    public void setOnPageChangeListener(OnPageChangeListener aVar) {
        this.ॱᐝ = aVar;
    }

    public void onPageScrolled(int i, float f, int i2) {
        if (this.ॱᐝ != null) {
            this.ॱᐝ.onPageScrolled(i, f, i2);
        }
    }

    public void onPageScrollStateChanged(int i) {
        if (this.ˈ) {
            ॱ(i);
        } else {
            ˊॱ();
        }
        if (this.ॱᐝ != null) {
            this.ॱᐝ.onPageScrollStateChanged(i);
        }
    }

    public void onPageScrolled(int i) {
        switch (i) {
            case 0:
            case 2:
                if (this.ˋ > 0.0f) {
                    ˋ();
                    break;
                }
                break;
            case 1:
                ॱ();
                break;
        }
        if (this.ॱᐝ != null) {
            this.ॱᐝ.onPageScrolled(i);
        }
    }

    private void ˋ(int i) {
        this.ॱˋ = i;
        ᐝ();
        requestLayout();
        invalidate();
    }

    private void ᐝ() {
        ˎ(getPaddingLeft(), getMeasuredWidth() - getPaddingRight(), ͺ());
        if (this.ˊˋ == 1) {
            ॱˊ();
        } else if (this.ˊˋ == 2) {
            ॱॱ();
        }
        this.ʿ = new float[this.ॱˋ];
        ʻ();
        this.ʻॱ = ((float) getMeasuredHeight()) / 2.0f;
        ˊॱ();
    }

    private void ˎ(int i, int i2, float f) {
        this.ˋˋ = (((float) i) + ((((float) (i2 - i)) - f) / 2.0f)) + (this.ˋॱ / 2.0f);
    }

    private void ʻ() {
        for (int i = 0; i < this.ॱˋ; i++) {
            this.ʿ[i] = this.ˋˋ + (((float) i) * (this.ʻ + this.ॱॱ));
        }
    }

    private void ॱॱ() {
        this.ˋˋ = ((this.ˋˋ * 2.0f) + this.ॱॱ) - ((float) epv.ˋ(getContext(), 16));
    }

    private void ॱˊ() {
        this.ˋˋ = ((this.ʻ - this.ॱॱ) - (this.ˋॱ / 2.0f)) + ((float) epv.ˋ(getContext(), 16));
    }

    private void ˊॱ() {
        if (this.ॱˋ != 0) {
            this.ॱˎ = this.ᐝॱ != null ? this.ᐝॱ.getCurrentItem() % this.ॱˋ : 0;
            if (this.ॱˋ > 0 && this.ʿ != null && this.ʿ.length > this.ॱˎ) {
                this.ʼॱ = this.ʿ[this.ॱˎ];
            }
        }
    }

    protected void onMeasure(int i, int i2) {
        int ˋॱ = ˋॱ();
        switch (MeasureSpec.getMode(i2)) {
            case Integer.MIN_VALUE:
                ˋॱ = Math.min(ˋॱ, MeasureSpec.getSize(i2));
                break;
            case 1073741824:
                ˋॱ = MeasureSpec.getSize(i2);
                break;
        }
        setMeasuredDimension(i, ˋॱ);
        ᐝ();
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        setMeasuredDimension(i, i2);
        ᐝ();
    }

    private int ˋॱ() {
        return (((int) (((float) (this.ˎ + this.ˊ)) + this.ˋॱ)) + getPaddingTop()) + getPaddingBottom();
    }

    private float ͺ() {
        return ((((float) this.ॱˋ) * this.ʻ) + (this.ˋॱ - this.ʻ)) + (((float) (this.ॱˋ - 1)) * this.ॱॱ);
    }

    protected void onDraw(Canvas canvas) {
        if (this.ॱˋ >= 2) {
            ˏ(canvas);
            ˎ(canvas);
        }
    }

    public void setIsRecycle(boolean z) {
        this.ˏ = z;
    }

    private void ˏ(Canvas canvas) {
        if (canvas == null) {
            Logger.ˋ("HwTopBannerIndicator", "drawUnselected, the canvas is null.");
            return;
        }
        for (int i = 0; i < this.ॱˋ; i++) {
            canvas.drawCircle(this.ʿ[i], this.ʻॱ, this.ˊॱ, this.ʽॱ);
            canvas.drawCircle(this.ʿ[i], this.ʻॱ, this.ˊॱ, this.ˋˊ);
        }
    }

    private void ˎ(Canvas canvas) {
        if (canvas == null) {
            Logger.ˋ("HwTopBannerIndicator", "drawSelected, the canvas is null.");
            return;
        }
        canvas.drawCircle(this.ʼॱ, this.ʻॱ, this.ˋॱ / 2.0f, this.ˉ);
        canvas.drawCircle(this.ʼॱ, this.ʻॱ, this.ˋॱ / 2.0f, this.ˋˊ);
    }

    private void ॱ(int i) {
        if (i == this.ॱˎ || this.ॱˋ == 0) {
            Logger.ˋ("HwTopBannerIndicator", "setSelectedPage : mCurrentPage = " + this.ॱˎ + ", now = " + i + ", mPageCount = " + this.ॱˋ);
            return;
        }
        this.ॱˎ = i;
        ˊॱ();
        invalidate();
    }

    private void ˏॱ() {
        try {
            Field declaredField = ViewPager.class.getDeclaredField("mScroller");
            declaredField.setAccessible(true);
            this.ˍ = new dkp(this.ᐝॱ.getContext());
            declaredField.set(this.ᐝॱ, this.ˍ);
            declaredField.setAccessible(false);
        } catch (Throwable e) {
            Logger.ˋ("HwTopBannerIndicator", "NoSuchFieldException", e);
        } catch (Throwable e2) {
            Logger.ˋ("HwTopBannerIndicator", "IllegalArgumentException", e2);
        } catch (Throwable e22) {
            Logger.ˋ("HwTopBannerIndicator", "IllegalAccessException", e22);
        }
    }

    public void setScrollDuration(int i) {
        if (this.ˍ != null) {
            if ((this.ˋ * 2.0f) / 3.0f < ((float) i)) {
                i = (((int) this.ˋ) * 2) / 3;
            }
            this.ˍ.ॱ(i);
        }
    }

    public void setIsNeedChangeViewPagerScrollDuration(boolean z) {
        this.ˋᐝ = z;
    }

    public void setmFragmentSelected(boolean z) {
        this.ʾ = z;
    }

    public int ˏ() {
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            return ((this.ॱˋ - (300 % this.ॱˋ)) + 300) - 1;
        }
        return (this.ॱˋ - (300 % this.ॱˋ)) + 300;
    }
}
